package com.wawei.seeds.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.wawei.seeds.R;
import com.wawei.seeds.model.UserInfo;
import com.wawei.seeds.views.NoScrollGridView;
import com.wawei.seeds.views.NoScrollListView;

import java.util.List;

/**
 * Created by itachi on 15/7/17.
 */
public class CommentListAdapter extends BaseAdapter {
    private List<UserInfo> list;
    private Context context;

    public CommentListAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<UserInfo> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public UserInfo getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.friends_circle_item, parent, false);
            holder.gridView = (NoScrollGridView) convertView
                    .findViewById(R.id.gridView);
            holder.listView = (NoScrollListView) convertView
                    .findViewById(R.id.lv_comment);
            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();

        if (list != null && list.size() > 0) {
            UserInfo mUserInfo = getItem(position);
            holder.gridView.setVisibility(View.VISIBLE);
            holder.gridView.setAdapter(new CommentGridAdapter(mUserInfo.ui,
                    context));
            holder.gridView
                    .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent,
                                                View view, int position, long id) {
                            // imageBrower(position,bean.urls);
                        }
                    });

            if (mUserInfo.comments != null && !mUserInfo.comments.isEmpty()) {
                holder.listView.setVisibility(View.VISIBLE);
                holder.listView.setAdapter(new CommentItemAdapter(mUserInfo.comments, context));
            }
        }
        return convertView;
    }

    public class ViewHolder {
        LinearLayout mContentimg;
        NoScrollGridView gridView;
        NoScrollListView listView;
    }
}
